//
//  XMFindViewController.m
//  XunMi
//
//  Created by MacBook on 2024/2/18.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMFindViewController.h"
#import <JXCategoryView/JXCategoryView.h>

#import "XMDaZiViewController.h"
#import "XMDynamicViewController.h"
#import "XMActivityViewController.h"
#import "XMGuanXuanViewController.h"
#import "XMTopicViewController.h"

@interface XMFindViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;

@end

@implementation XMFindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSubviews];
}

#pragma mark - setupSubViews
- (void)setupSubviews {
    [self.navLeftBtn setImage:nil forState:UIControlStateNormal];
//    UIImageView *logo = [[UIImageView alloc] initWithImage:kGetImage(@"find_navlogo")];
//    [self.navView addSubview:logo];
//    [logo mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.navView).offset(22);
//        make.size.mas_equalTo(CGSizeMake(28, 21));
//        make.centerY.equalTo(self.navTitleLa).offset(-4);
//    }];
//    
    [self.navView addSubview:self.categoryView];
    self.categoryView.listContainer = self.listContainerView;

    [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.navView).offset(15);
        make.right.equalTo(self.navView).offset(-15);
        make.top.equalTo(self.navView).offset(kStatusBarHeight);
        make.height.mas_equalTo(44);
    }];

    [self.view addSubview:self.listContainerView];
    [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(kNavBarAndStatusBarHeight, 0, 0, 0));
    }];

    [self.listContainerView.scrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
}

#pragma mark - JXCategoryListContainerViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return 2;
}

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    switch (index) {
//        case 0:
//        {
//            XMDaZiViewController *vc = [[XMDaZiViewController alloc] init];
//            vc.view.backgroundColor = kRandomColor;
//            return vc;
//
//        }
//            break;
        case 0:
        {
            XMDynamicViewController *vc = [[XMDynamicViewController alloc] init];
            return vc;
            
        }
            break;
        case 1:
        {
            XMActivityViewController *vc = [[XMActivityViewController alloc] init];
            return vc;
            
        }
            break;
//        case 2:
//        {
//            XMGuanXuanViewController *vc = [[XMGuanXuanViewController alloc] init];
//            return vc;
//            
//        }
//            break;
//        case 4:
//        {
//            XMTopicViewController *vc = [[XMTopicViewController alloc] init];
//            vc.view.backgroundColor = kRandomColor;
//            return vc;
//            
//        }
//            break;
        default:
            return nil;
            break;
    }
    
    
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}

#pragma mark - JXPagerMainTableViewGestureDelegate
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
        return NO;
    }
    return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}

#pragma mark - Getter
- (JXCategoryTitleView *)categoryView {
    if (_categoryView == nil) {
        _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kNavBarHeight)];
        _categoryView.backgroundColor = [UIColor clearColor];
        _categoryView.delegate = self;
        _categoryView.titleColor = kHEX(@"#1F1F1F");
        _categoryView.titleSelectedColor = kAppMainColor;
        _categoryView.titleFont = [UIFont fontWithName:@"PingFangSC-Semibold" size:14];
//        _categoryView.titleSelectedFont = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];

        _categoryView.titleColorGradientEnabled = YES;
        _categoryView.titleLabelZoomEnabled = YES;
//        _categoryView.titleLabelZoomScale = 1.0;
        _categoryView.titleLabelStrokeWidthEnabled = YES;

        JXCategoryIndicatorImageView *indicatorImageView = [[JXCategoryIndicatorImageView alloc] init];
        indicatorImageView.indicatorImageView.image = [UIImage imageNamed:@"bag_line"];
        indicatorImageView.indicatorImageViewSize = CGSizeMake(14, 6);
        indicatorImageView.verticalMargin = 5;
        _categoryView.indicators = @[indicatorImageView];
        _categoryView.titles = @[@"动态", @"活动"];

//        _categoryView.titles = @[@"动态", @"活动", @"官宣"];

//        _categoryView.titles = @[@"寻搭子", @"动态", @"活动", @"官宣", @"话题"];
    }
    return _categoryView;
}

- (JXCategoryListContainerView *)listContainerView {
    if (!_listContainerView) {
        _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    }
    return _listContainerView;
}
@end
